<?php
class SessionManager
{
    private $session;

    public function __construct()
    {
        $this->session = new Zend_Session_Namespace('storeutils');
    }

    public function get($key, $bMandatory=false)
    {
        $value = $this->session->$key;

        if (empty($value) && $bMandatory)
        {
            throw new Exception('Not found in session: '.$key);
        }

        return $value;
    }

    public function set($key, $value)
    {
        $this->session->$key = $value;
    }

    public function getCurrentStore()
    {
        return $this->get('storeUri', true);
    }

    public function setCurrentStore($storeUri)
    {
        $this->set('storeUri', $storeUri);
    }

    public function resetCurrentStore()
    {
        unset($this->session->storeUri);
    }

    public function getRecentQueries()
    {
        if (!isset($this->session->recentQueries))
        {
            $this->session->recentQueries = array();
        }

        return $this->session->recentQueries;
    }

    public function addRecentQuery($query)
    {
        $queries = $this->getRecentQueries();

        if (array_search($query, $queries) === FALSE)
        {
            $queries[] = $query;
            $this->session->recentQueries = $queries;
        }
    }

    public function getRecentURIs()
    {
        if (!isset($this->session->recentURIs))
        {
            $this->session->recentURIs = array();
        }

        return $this->session->recentURIs;
    }

    public function addRecentURI($uri)
    {
        $uris = $this->getRecentURIs();
        $uris[] = $uri;
        $this->session->recentURIs = $uris;
    }

}